package com.paisheng.justlife.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.paisheng.justlife.R;

import java.util.Timer;
import java.util.TimerTask;

public class CloseBoorActivity extends Activity{

   private Button btn_return;
   private TextView tv_time;
    private int recLen = 60;
    Timer timer = new Timer();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_close_door);
        btn_return = (Button)findViewById(R.id.btn_return);
        tv_time = (TextView)findViewById(R.id.tv_time);
        btn_return.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(CloseBoorActivity.this,MainActivity.class));
            }
        });
        tv_time.setText(recLen+"");

    }
    @Override
    protected void onResume() {
        super.onResume();
        timer.schedule(task, 1000, 1000);
    }

    public TimerTask task = new TimerTask() {
        @Override
        public void run() {

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    recLen--;
                    tv_time.setText("" + recLen);
                    if (recLen <= 0) {
                        startActivity(new Intent(CloseBoorActivity.this,MainActivity.class));
                        timer.cancel();
                    }
//                    Log.e("zpan","======remainTime=====" + recLen);

                }
            });

        }
    };

    @Override
    protected void onPause() {
        super.onPause();
        timer.cancel();
        finish();
    }

}
